import { AgentRole, AgentStatus, CpuInfo, DriveInfo, MemoryInfo } from '../type';
import { BaseEntity } from '../../../shared/baseEntity';
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';


@Entity('agents')
export class Agent extends BaseEntity {

  @PrimaryGeneratedColumn()
    id: number;

  @Column({ unique: true })
  public identity: string;

  @Column()
  public desc: string;

  @Column()
  public advertise_ip: string;

  @Column()
  public port: number;

  @Column({
    type: 'enum',
    enum: AgentStatus
  })
  public status: AgentStatus;

  @Column('text', { array: true })
  public products: string[];

  @Column({
    type: 'enum',
    enum: AgentRole,
    default: AgentRole.PUBLIC
  })
  public role: AgentRole;

  @Column({
    nullable: true
  })
  public password: string;

  @Column({
    type: 'json',
    nullable: true
  })
  public cpu: CpuInfo;

  @Column({
    type: 'json',
    nullable: true
  })
  public drive: DriveInfo;

  @Column({
    type: 'json',
    nullable: true
  })
  public memory: MemoryInfo;

  @Column({
    type: 'timestamptz',
    nullable: true
  })
  public disconnected_at: Date;

}